package com.ajie.slimming.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ajie.slimming.R;
import com.ajie.slimming.base.BaseListAdapter;
import com.ajie.slimming.bean.UserInfoItem;

public class UserInfoListAdapter extends BaseListAdapter<UserInfoItem>
{
    
    public UserInfoListAdapter(Context context)
    {
        super(context);
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder viewHolder = null;
        
        if (null == convertView)
        {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.fragment_user_info_list_item,
                    parent,
                    false);
            viewHolder.name = (TextView) convertView.findViewById(R.id.name);
            viewHolder.value = (TextView) convertView.findViewById(R.id.value);
            convertView.setTag(viewHolder);
        }
        else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        UserInfoItem info = getItem(position);
        if (null != info)
        {
            viewHolder.name.setText(info.getName());
            if (TextUtils.isEmpty(info.getValue()))
                viewHolder.value.setHint("点击填写");
            else
            {
                switch (position)
                {
                    case 1:
                        viewHolder.value.setText(info.getValue() + "cm");
                        break;
                    case 2:
                        viewHolder.value.setText(info.getValue() + "kg");
                        break;
                    case 3:
                        viewHolder.value.setText(info.getValue() + "岁");
                        break;
                    default:
                        viewHolder.value.setText(info.getValue());
                        break;
                }
            }
        }
        return convertView;
    }
    
    class ViewHolder
    {
        TextView name;
        
        TextView value;
    }
    
    public String getValue(int position)
    {
        return getItem(position).getValue();
    }
}
